package com.fare.taluo.core.domain.crawl;

import java.sql.Date;
import java.util.List;

import javax.persistence.Column;

import com.dayatang.domain.Entity;
import com.dayatang.domain.InstanceFactory;
import com.dayatang.domain.QuerySettings;
import com.fare.taluo.base.ddd.domain.baseentity.BaseEntity2;
/**
 * 抓取统计（存储持久化数据）
 * for grabDate
 * @author gan
*/
@javax.persistence.Table(name="FDC_CRAWL_STATISTICS_GRABDATE")
@javax.persistence.Entity
public class FdcCrawlStatisticsForGrabDateEntity extends BaseEntity2<FdcCrawlStatisticsForGrabDateEntity> implements Entity{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Column(name="create_time")
	private Date createTime;
	
	@Column(name ="grab_date")
	private Date grabDate;
	
	@Column(name ="day_source_data")
	private Long dayTotalSourceData;
	
	@Column(name ="day_line_numbers")
	private Long dayTotalLineNumbers;
	
	@Column(name ="line_by_channel")
	private String lineByChannel;
	
	@Column(name ="source_by_channel")
	private String sourceByChannel;
	
	@Column(name ="line_city_by_channel")
	private String lineCityByChannel;
	
	
	private static FdcCrawlStatisticsEntityRepository getFdcCrawlStatisticsEntityRepository(){
		return InstanceFactory.getInstance(FdcCrawlStatisticsEntityRepository.class);
	}
	
	/**
	 * 执行存入数据(持久化数据)
	 * for grabDate 
	 */	
	public  void saveDatasForGrabDate(List<FdcCrawlStatisticsForGrabDateEntity> entityList){
		getFdcCrawlStatisticsEntityRepository().saveDatasForGrabDate(entityList);
	}
	/**
	 * delete by grabDate
	*/
	public void deleteEntityByGrabDate(Date grabDate){
		getFdcCrawlStatisticsEntityRepository().deleteEntityByGrabDate(grabDate);
	}
	/**
	 * update by grabDate
	*/
	public void updateDatasForGrabDate(List<FdcCrawlStatisticsForGrabDateEntity> entityList){
		getFdcCrawlStatisticsEntityRepository().updateDatasForGrabDate(entityList);
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getGrabDate() {
		return grabDate;
	}

	public void setGrabDate(Date grabDate) {
		this.grabDate = grabDate;
	}

	public Long getDayTotalSourceData() {
		return dayTotalSourceData;
	}

	public void setDayTotalSourceData(Long dayTotalSourceData) {
		this.dayTotalSourceData = dayTotalSourceData;
	}

	public Long getDayTotalLineNumbers() {
		return dayTotalLineNumbers;
	}

	public void setDayTotalLineNumbers(Long dayTotalLineNumbers) {
		this.dayTotalLineNumbers = dayTotalLineNumbers;
	}

	public String getLineByChannel() {
		return lineByChannel;
	}

	public void setLineByChannel(String lineByChannel) {
		this.lineByChannel = lineByChannel;
	}

	public String getSourceByChannel() {
		return sourceByChannel;
	}

	public void setSourceByChannel(String sourceByChannel) {
		this.sourceByChannel = sourceByChannel;
	}

	public String getLineCityByChannel() {
		return lineCityByChannel;
	}

	public void setLineCityByChannel(String lineCityByChannel) {
		this.lineCityByChannel = lineCityByChannel;
	}

	@Override
	public boolean isNew() {
		return getId() == null ;
	}

	@Override
	public boolean existed() {
		if (isNew()) {
			return false;
		}
		return getRepository().exists(getClass(), id);
	}

	@Override
	public boolean notExisted() {
		return ! existed();
	}

	@Override
	public boolean existed(String propertyName, Object propertyValue) {
		List<?> entities = getRepository().find(QuerySettings.create(getClass()).eq(propertyName, propertyValue)); 
		return !(entities.isEmpty());
	}

	private static FdcCrawlStatisticsForGrabDateEntityRepository getForGrabDateEntityRepository(){
		return  InstanceFactory.getInstance(FdcCrawlStatisticsForGrabDateEntityRepository.class);
	}
	
	public List<FdcCrawlStatisticsForGrabDateEntity> findByGrabDate(Date date1, Date date2,Date grabDate) {
		return getForGrabDateEntityRepository().findByGrabDate(date1, date2,grabDate);
	}
	
	
}
